#pragma once

#define DEVICE_DESCRIPTION ((L"Transformer TF101"))
#define CLIENT_NAME ((L"mtpinterface"))

class MTPconnect
{
public:
    enum ERRORCODE { SUCCESS, UNSPEC_ERROR, CONNECT_FAIL, CONNECT_SUCCESS, FILE_OPEN_FAIL, PROPERTY_CREATE_FAIL, NULL_POINTER, GUI_QUIT, DISCONNECT, NO_FILE_ERROR };
    enum FILE_TYPE { FT_PIC, FT_VID, FT_AUD, FT_XML, FT_TXT };
    enum MESSAGE_TYPE { M_INFO, M_IMPORTANT, M_ERROR, M_STATUS };

    MTPconnect(void);
    ~MTPconnect(void);

    ERRORCODE connect();
    LPWSTR setDir(LPCWSTR dir);
    LPWSTR createDir(LPWSTR parentID, LPWSTR folderName);
    ERRORCODE writeFile(LPWSTR parentFolder, LPWSTR path, FILE_TYPE ft);
    WCHAR * getFile(LPWSTR parentID, LPWSTR fileName = L"artour.xml");
    bool checkExists(LPWSTR parentID, LPWSTR fileName);
    ERRORCODE deleteObj(LPWSTR parentID, LPWSTR objName, bool recursive = false);
    ERRORCODE renameFolderObj(LPWSTR parentID, LPWSTR objName, LPWSTR newObjName);
    LPWSTR getFileNameFromPath(LPWSTR path);
    void getRootFolder(LPWSTR rootID, LPWSTR localPath);
    WCHAR * getObject(LPWSTR objID, LPWSTR localPath);

private:
    HRESULT hr;
    CComPtr<IPortableDeviceManager> devMgr;
    CComPtr<IPortableDevice> device;
    CComPtr<IPortableDeviceProperties> devProp;
    CComPtr<IPortableDeviceValues> devInfo;
    CComPtr<IPortableDeviceContent> devContent;
    CComPtr<IPortableDeviceKeyCollection> keys;
    LPWSTR artourFolderID;
    PortDevEventCallback *devcb;

    LPWSTR getDevPath();
    HRESULT connectToDev(LPWSTR path);
    ERRORCODE getProperties(FILE_TYPE ft, LPWSTR parentFolderID, LPWSTR path, IStream *fileStream, IPortableDeviceValues **values);
    WCHAR * getTmpFileName();
    HRESULT copyStream(IStream *input, IStream *output, DWORD bufSize, DWORD *bytesWritten);
};

